/**
 * 积分明细
 */
import 'package:cbec_app/components/base/base_page.dart';
import 'package:cbec_app/components/common/common_style.dart';
import 'package:cbec_app/components/base/base_nav_bar.dart';
import 'package:cbec_app/components/common/not_found.dart';
import 'package:cbec_app/pages/member/controller/member_ctr.dart';
import 'package:cbec_app/utils/Tools.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class ScoreLog extends GetView<MemberController> {
  ScoreLog({super.key});


  @override
  Widget build(BuildContext context) {
    return GetBuilder<MemberController>(builder: (controller){
      return BasePage(
      title: "积分明细",
      iconType: IconType.back,
      children: [
        Container(
            child: Column(
          children: [
            Container(
              color: Colors.white,
              child: TabBar(
                  indicator: BoxDecoration(
                      border: Border(
                          bottom: BorderSide(color: Colors.red, width: 1.0))),
                  labelColor: Colors.red,
                  labelPadding: EdgeInsets.zero,
                  controller: controller.typeTabController,
                  tabs: [
                    Tab(text: '全部'),
                    Tab(text: '收入'),
                    Tab(text: '支出'),
                  ]),
            ),
            Container(
              height: 570.h,
              color: Colors.white,
              margin: EdgeInsets.only(top: 10.w),
              child: controller.logList.isNotEmpty? Tools.getPullRefresh(
                  enablePullDown: true,
                  enablePullUp: controller.hasNextPage,
                  refreshController: controller.baseRefreshCtr,
                  onRefresh: controller.onPageRefresh,
                  onLoading: controller.onPageLoading,
                  child: ListView.builder(
                    itemCount: controller.logList.length,
                    shrinkWrap: true,
                    itemBuilder: (context,index){

                      final Map item = controller.logList[index];
                    return ScoreLogItem(title: item['detail'], time: item['createTime'], amount: item['quantity'].toString(), status: item['type']==0?true:false);
                  })
              ):const NotFound()
                  // ListView(
                  //   children: [
                  //     ScoreLogItem(title: "邀请有礼", time: "2023-03-01 12:22:00", amount: "7", status: true),
                  //     ScoreLogItem(title: "下单积分抵扣", time: "2023-03-01 12:22:00", amount: "17", status: false),
                  //   ],
                  // )
            )
          ],
        ))
      ],
    );
    });
  }
}

/**
 * 金额文本组件
 */
class ScoreLogItem extends StatelessWidget {
  final String title; //标题
  final String time; //金额时间
  final String amount; //金额
  final bool status; //类型 true是收入 false是支出

  const ScoreLogItem(
      {super.key,
      required this.title,
      required this.time,
      required this.amount,
      required this.status});
  final TextStyle titleStyle = const TextStyle(
      fontSize: 12, fontWeight: FontWeight.bold, color: Colors.black);
  final TextStyle surplusTitleStyle = const TextStyle(
      fontSize: 10, fontWeight: FontWeight.bold, color: Colors.black);
  final TextStyle subTitleStyle = const TextStyle(
      fontSize: 10,
      fontWeight: FontWeight.w400,
      color: Color.fromRGBO(153, 153, 153, 1));
  final TextStyle amountAddTitleStyle = const TextStyle(
      fontSize: 14,
      fontWeight: FontWeight.w700,
      color: Color.fromRGBO(7, 193, 96, 1));
  final TextStyle amountdecTitleStyle = const TextStyle(
      fontSize: 14,
      fontWeight: FontWeight.w700,
      color: Color.fromRGBO(248, 63, 45, 1));

  @override
  Widget build(BuildContext context) {
    String _type = '+';
    TextStyle _amountColor = amountAddTitleStyle;
    if (status) {
      _type = '+';
      _amountColor = amountAddTitleStyle;
    } else {
      _type = '-';
      _amountColor = amountdecTitleStyle;
    }

    return Container(
      padding: EdgeInsets.all(18.w),
      decoration: bottom_gary_border,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          //左边是4列的文本
          SizedBox(
            // alignment: Alignment.topLeft,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  title,
                  style: titleStyle,
                ),
                SizedBox(
                  height: 5.h,
                ),
                Text(
                  time,
                  style: subTitleStyle,
                ),
              ],
            ),
          ),
          //右边的数字
          SizedBox(
            child: Text("$_type$amount", style: _amountColor),
          )
        ],
      ),
    );
  }
}
